<?php
/**
 * Created by PhpStorm.
 * User:王加明
 * Date: 2017-04-13
 * Time: 下午 1:40
 */
namespace app\hongyanche\controller;
class MaintainAdmin{
    private $auth;
    public function __construct()
    {
        model('product')->demand('maintain');
        if (!model('admin')->is('maintain')['state']) {
            $res = array('state' => 0, 'errormsg' => 'authority incorrect', 'errorcode' => '');
            $this->auth = $res;
        }else{
            $this->auth = array('state'=>1);
        }
    }
    //查看申请信息
    function info(){

    }
    //查看申请记录列表
    function apply_list(){

    }
    //查看订单记录列表
    function maintain_order_list(){

    }
    //查看评价
    function comment_list(){

    }
    //筛选评价
    function screen_comment(){

    }
    //回复
    function reply(){

    }
    //开关定时器
    function time_switch(){
        $b = input('num');
        //文件路径
        $file = $_SERVER['DOCUMENT_ROOT'].'/_hongyanche/switch.txt';
        //写入文件内容0
        file_put_contents($file,$b);
        $a = file_get_contents($file);
        if($a == 1){
            model('maintain')->timer();
        }
    }

    //添加站点类别
    public function label_add()
    {
        $cn = input('cn');
        $res = model('maintain')->label_add($cn);
        return json($res);
    }
    //获取类别列表
        public function label_list()
    {
        $res = model('maintain')->label_list();
        return json($res);
    }
    //删除站点
    public function label_remove()
    {
        $label_id = input('label_id');
        $res = model('maintain')->label_remove($label_id);
        return json($res);
    }
    //修改类别名字
    public function label_rename()
    {
        $label_id = input('label_id');
        $newname = input('newname');
        $res = model('maintain')->label_rename($label_id,$newname);
        return json($res);
    }
//------------------------------------站点---------------------------------
    //管理员创建
    public function add()
    {
        $data['cust_code'] = input('cust_code');
        $data['cust_name'] = input('cust_name');
        $data['company_tel'] = input('company_tel');
        $data['province'] = input('province');
        $data['city'] = input('city');
        $data['area'] = input('area');
        $data['company_address'] = input('company_address');
        $data['cust_type'] = input('cust_type');
        $res = model('maintain')->add($data);
        return json($res);
    }
    //修改
    public function modify()
    {
        $cust_code = input('cust_code');
        $data['cust_name'] = input('cust_name');
        $data['cust_code'] = input('cust_code');
        $data['company_tel'] = input('company_tel');
//        $data['lng'] = input('lng');
//        $data['lat'] = input('lat');
        $data['lant'] = input('lant');
        $data['province'] = input('province');
        $data['city'] = input('city');
        $data['area'] = input('area');
        $data['company_address'] = input('company_address');
        $res = model('Maintain')->modify($cust_code,$data);
        return json($res);
    }
    //删除
    public function remove()
    {
        $id = input('cust_code');
        $res = model('Maintain')->remove($id);
        return json($res);
    }
    //开放关闭
    public function release()
    {
        $id = input('cust_code');
        $release = input('release');
        $res = model('Maintain')->release($id,$release);
        return json($res);
    }
    //列表
    public function getlist()
    {
        $filter['page'] = input('page');
        $filter['keywords'] = input('keywords');
        $filter['cust_type'] = input('cust_type');
        $res = model('Maintain')->maintain_list($filter);
        return json($res);
    }
    //站点详细
    public function getinfo()
    {
        $cust_code = input('cust_code');
        $res = model('maintain')->getinfo($cust_code);
        return json($res);
    }

    //合并配件信息进mall表
    public function merge_parts()
    {
        $res = model('Maintain')->merge_parts();
        return json($res);
    }

    //合并配件网店进maintain_pj_cust表
    public function merge_cust()
    {
        $res = model('Maintain')->merge_cust();
        return json($res);
    }
    //---------------------------------------车辆-------------------------------
    public function vehicle_modify()
    {
        if (!empty($this->auth) && !$this->auth['state']) return json($this->auth);
        $id = input('customer_id');
        $data=[
            'vin'=> input('vin'),
            'uname'   =>input('uname'),
            'vehicle_license_province'=> input('vehicle_license_province'),
            'vehicle_license_number'=> input('vehicle_license_number'),
            'role'=>input('role'),
            'vehicle_brand'=> input('vehicle_brand'),
            'driving_card'=> input('driving_card')
        ];
        $res = model('maintain')->vehicle_modify($id,$data);
        return json($res);
    }

    public function vehicle_remove()
    {
        if (!empty($this->auth) && !$this->auth['state']) return json($this->auth);
        $id = input('customer_id');
        $res = model('maintain')->vehicle_remove($id);
        return json($res);
    }

    public function vehicle_list()
    {
        if (!empty($this->auth) && !$this->auth['state']) return json($this->auth);
        $filter['page'] = input('page');
        $filter['keywords'] = input('keywords');
        $filter['admin'] = 1;
        $res = model('maintain')->vehicle_list($filter);
        return json($res);
    }

    public function vehicle_info()
    {
        if (!empty($this->auth) && !$this->auth['state']) return json($this->auth);
        $id = input('customer_id');
        $res = model('maintain')->vehicle_info($id);
        return json($res);
    }
}